package com.yipao.wx.service;


import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yipao.core.system.LbsConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


/**
 * 腾讯地图云存储API
 *
 * @author y.x
 * @date 2019/9/16
 */
@Service
public class LbsTableService {


    @Value("${wx.login.tableId}")
    private String tableId;

    @Value("${wx.login.key}")
    private String key;

    @Value("${wx.login.radius}")
    private String radius;


    public Object searchNearBy(String location){
        Map<String,Object> map=new HashMap<>();
        map.put("location",location);
        map.put("radius",radius);
        map.put("table_id",tableId);
        map.put("key",key);
        StringBuilder builder = new StringBuilder(LbsConstant.NEARBY_SEARCH_URL);
        boolean isFirst = true;
        for (String key : map.keySet()) {
            if (key != null && map.get(key) != null) {
                if (isFirst) {
                    isFirst = false;
                    builder.append("?");
                } else {
                    builder.append("&");
                }
                builder.append(key)
                        .append("=")
                        .append(map.get(key));
            }
        }

        return JSON.parseObject(HttpUtil.get(builder.toString()));
    }




}
